<pre>
<?php //print_r($survey); ?>
</pre>

<?php /*if(isset($assign_result["state"]) && $assign_result["state"] == 1): ?>
    <span style="text-align: center;">La encuesta ya fue finalizada! Gracias</span>
    <?php die(); ?>
<?php endif;*/?>

<?php use_stylesheet("themes/survey_default.css"); ?>

<script type="text/javascript" >
    var config_assig = ({
        assig_id : '<?php echo $survey["_id"]; ?>',
        save_ajax_question : "<?php echo url_for("survey/SaveAnswerSurvey");?>"
    });
</script>

<script type="text/javascript" >
    $(document).ready(function(){
        //validate Form
        $("#survey-assig-form").validate({ });
        //Submit form
        $("#save_form_survey").click(function(){
            if ($("#survey-assig-form").valid()) { if( confirm("¿ Esta seguro de enviar la evaluación ?") ){ $("#survey-assig-course").submit(); }else{  return false; }
            }else{$.jGrowl("Existen preguntan sin responder, por favor diligencia todo el formulario. Gracias",{ header: 'Error',theme: "error"});return false;}
        });
        
        $("#survey-assig-form td.question_structure input").addClass("required").change(function(){
            var input = $(this);
            var q= input.attr("name");
            var v= input.val();
            $.post(config_assig.save_ajax_question, { aid:config_assig.assig_id , q:q,v:v});
        });

    });
    function saveAnswer(q,v){$.post(config_assig.save_ajax_question, { acid:config_assig.assig_id , q:q,rate:v } );}
    function cancelForm(){
        window.location = '<?php echo sfConfig::get("app_URLMoodle"); ?>';
    }
</script>

<div id="wrapper-content-survey">
    <div class="header">
        <div class="info">VICERRECTORÍA ACADÉMICA DIRECCIÓN DE DOCENCIA</div>
        <div class="logo"><?php echo image_tag("utb_logo");?></div>
        <div class="info2">
            <span class="survey-name"><?php echo $survey["name"] ?></span>
            <span class="date">Fecha: <?php echo date("d-m-Y"); ?></span>
        </div>
    </div>
    <div class="survey-description">
        <?php echo html_entity_decode($survey["description"]); ?>
    </div>
    <div class="content-body-survey">

        <form id="survey-assig-form" action="<?php echo url_for("survey/FinishSurvey"); ?>" method="POST">
            <input name="aid" value="<?php echo $assignment["_id"]; ?>" type="hidden" />
            <?php foreach($survey["groups"] as $key=>$group): ?>
            <div class="content-group" id="group-<?php echo $group["key"]; ?>" class="group">
                <div class="title"><?php echo $group["description"];?></div>
                <table class="content-question">
                    
                <?php foreach($group["questions"] as $key=>$question):?>
                    <?php $h=0; ?>
                    <tr>
                        <td class="index">
                            <?php echo $question["key"]?>
                        </td>
                        <td class="text">
                            <?php echo $question["text"]?>
                        </td>
                    </tr>
                    <tr >
                        <td class="question_structure"colspan="2">
                            <?php $sf_user->getStructureQuestion($question["type"]["name"],$question["type"]["structure"],$question["key"]);?>
                        </td>
                    </tr>
                <?php endforeach; ?>
                </table>
            </div>
            <?php endforeach; ?>

            <div class="buttons">
                <input type="button" onclick="cancelForm();" value="Cancelar" id="cancel_form_survey">
                <input type="button" value="Guardar" id="save_form_survey">
            </div>

        </form>
    </div>

</div>

